package com.efast.dmom.mes.datahandlers.entity;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.dmom.mes.bean.QualityCheckOperation;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.dao.entity.QualityCheckOperationDao;
import com.efast.dmom.mes.datahandlers.base.QualityBaseDataHandler;
import com.efast.dmom.mes.entity.QualityCheckOperationEntity;
import com.efast.dmom.mes.util.SpringWebUtils;
import com.efast.dmom.mes.util.TimeUtil;

@Component
public class QualityCheckOperationHandler extends QualityBaseDataHandler<QualityCheckOperation>{

	@Autowired
	private QualityCheckOperationDao QualityCheckOperationDao;
	@Override
	public ResultBean save(QualityCheckOperation obj) {
		obj.getInnerData().setSiteId(DataHandlerUtils.getSiteId());
		obj.getInnerData().setCreationTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setCreationTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setCreator(SpringWebUtils.getRequestUser());
		obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//	    obj.getInnerData().setCreationPid(DataHandlerUtils.getDmomPid());
//	    obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
		obj.getInnerData().setRowStatus(1);
		obj.getInnerData().setRowTrxId(1);
		QualityCheckOperationDao.save(obj.getInnerData());
		return null;
	}
	@Override
	public ResultBean update(QualityCheckOperation obj) {
		obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
		obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
		obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//	    obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
		obj.getInnerData().setRowTrxId(1);
		QualityCheckOperationDao.update(obj.getInnerData());
		return null;
	}
	@Override
	public ResultBean delete(QualityCheckOperation obj) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public QualityCheckOperation getById(long id) {
		QualityCheckOperation qualityCheckOperation = new QualityCheckOperation();
		qualityCheckOperation.setInnerData(QualityCheckOperationDao.getById(id));
		return qualityCheckOperation;
	}
	@Override
	public QualityCheckOperation getByName(String name) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public QualityCheckOperation getByCode(String code) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void batchDeleteById(List<QualityCheckOperation> list) {
		List<QualityCheckOperationEntity> objs = new ArrayList<QualityCheckOperationEntity>();
		for (QualityCheckOperation obj : list) {
			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//		    obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
			obj.getInnerData().setRowTrxId(1);
			objs.add(obj.getInnerData());
		}
		QualityCheckOperationDao.deleteBatch(objs);
	}

	public List<QualityCheckOperation> getByoperationAndCheck(QualityCheckOperation qualityCheckOperation) {
		List<QualityCheckOperation> list = new ArrayList<QualityCheckOperation>();
		List<QualityCheckOperationEntity> byoperationAndCheck = QualityCheckOperationDao.getByoperationAndCheck(qualityCheckOperation.getInnerData());
		if (byoperationAndCheck.size()>0) {
			byoperationAndCheck.forEach(item -> {
				QualityCheckOperation qualityCheckOperation2 = new QualityCheckOperation();
				qualityCheckOperation2.setInnerData(item);
				list.add(qualityCheckOperation2);
			});
		}
		return list;
	}
	@Override
	public ResultBean saveBatch(List<QualityCheckOperation> obj) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public ResultBean updateBatch(List<QualityCheckOperation> obj) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public ResultBean deleteBatch(List<QualityCheckOperation> obj) {
		// TODO Auto-generated method stub
		return null;
	}
	

}
